<?php

namespace App\Http\Resources;

use App\Http\Resources\Book as BookCollection;
use App\Http\Responses\Resource;

class WriteInfo extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {

        $books_count = $this->books()->count();
        $fans_count = $this->fans()->where('status','!=',1)->count();
        $posts_count = $this->posts()->count();

        return [
            'books_count' => $books_count,
            'fans_count' => $fans_count,
            'posts_count' => $posts_count,
            'books' => BookCollection::collection($this->books)
        ];

    }
}
